#include<iostream>
#include<list>
using namespace std;

//list容器赋值和交换

void printlist(const list<int>&L)
{
    for(auto it:L)
    {
        cout<<it<<" ";
    }
    cout<<endl;
}
//赋值
void test01()
{
    list<int> L1;

    L1.push_back(10);
    L1.push_back(20);
    L1.push_back(30);
    L1.push_back(40);
    printlist(L1);

    list<int> L2;
    L2=L1;
    printlist(L2);

    list<int> L3;
    //L3.assign(L2);   错误的，没有这种写法
    L3.assign(L2.begin(),L2.end());
    printlist(L3);

    list<int> L4;
    L4.assign(10,100);
    printlist(L4);
}

//交换
void test02()
{
    list<int> L1;

    L1.push_back(10);
    L1.push_back(20);
    L1.push_back(30);
    L1.push_back(40);

    list<int> L2;

    L2.assign(10,100);

    cout<<"交换前："<<endl;
    printlist(L1);
    printlist(L2);

    L1.swap(L2);
    cout<<"交换后："<<endl;
    printlist(L1);
    printlist(L2);

}



int main()
{
    test01();
    test02();
    return 0;
}
